package com.miyake.dsp.converter;

import com.miyake.dsp.ComplexArray;
import com.miyake.dsp.Processor;


public class LimiterImpl implements Processor {

	private ComplexArray source;
	private LimiterSetting setting;

	public LimiterImpl(LimiterSetting setting) {
		this.setting = setting;
	}
	
	@Override
	public void setSource(ComplexArray source) {
		this.source = source;
	}

	@Override
	public ComplexArray getSource() {
		return this.source;
	}

	@Override
	public ComplexArray getProcessed() {
		ComplexArray ret = new ComplexArray(source.getRealPart().clone(), 
				null /*source.getImagPart().clone()*/);
		
		for (int i = 0; i < ret.getRealPart().length; i++) {
			if (ret.getRealPart()[i] > setting.getMax()) {
				ret.getRealPart()[i] = setting.getMax();
			}
			if (ret.getRealPart()[i] < setting.getMin()) {
				ret.getRealPart()[i] = setting.getMin();
			}
		}
		return ret;
	}

	@Override
	public Object getSetting() {
		return setting;
	}

}
